/**
 * Project  : Looker
 * Package  : net.freestu.looker.common
 * File     : Media.java
 * Author   : solosky < solosky772@qq.com >
 * Date     : Jul 29, 2009
 * Modified : Jul 29, 2009
 * License  : Apache License 2.0 
 */
package net.freestu.looker.common;

import java.io.File;
import java.util.Date;

import net.freestu.looker.util.FileUtils;
import net.freestu.looker.util.HashUtils;
import net.freestu.looker.util.URLUtils;
import net.freestu.looker.util.FileUtils.FileType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 附件（真不知道怎么翻译了。。）
 * 新闻中所包含的图片，链接，视频，声音等信息
 * @author  solosky
 */
public class Media
{
	/**
	 * 附件类型
	 */
	public enum MediaType {IMAGE, VIDEO, SOUND, DOC, ZIP, OHTER};
	
	/**
	 * 附件编号
	 */
	private String hash;
	
	/**
	 * 附件地址
	 */
	private String url;
	
	/**
	 * 附件所属新闻
	 */
	private NewsEntity newsEntity;
	
	/**
	 * 附件大小
	 */
	private long size;
	
	/**
	 * 附件文件名
	 */
	private String name;
	
	/**
	 * 附加下载时间
	 */
	private Date date;
	
	/**
	 * 附件临时文件
	 */
	private File tmpFile;


	public String getHash()
    {
    	return hash;
    }

	public void setHash(String hash)
    {
    	this.hash = hash;
    }

	public String getUrl()
    {
    	return url;
    }

	public void setUrl(String url)
    {
    	this.url = url;
    	this.hash = HashUtils.longHash(url);
    	this.name = URLUtils.file(url);
    }


	public NewsEntity getNewsEntity()
    {
    	return newsEntity;
    }

	public void setNewsEntity(NewsEntity newsEntity)
    {
    	this.newsEntity = newsEntity;
    }

	public long getSize()
    {
    	return size;
    }

	public void setSize(long size)
    {
    	this.size = size;
    }

	public String getName()
    {
    	return name;
    }

	public void setName(String name)
    {
    	this.name = name;
    }

	public Date getDate()
    {
    	return date;
    }

	public void setDate(Date date)
    {
    	this.date = date;
    }

	public File getTmpFile()
    {
    	return tmpFile;
    }

	public void setTmpFile(File tmpFile)
    {
    	this.tmpFile = tmpFile;
    }

	public FileType getType()
    {
    	return FileUtils.fileType(FileUtils.extension(tmpFile.getName()));
    }
	
	public String toString()
	{
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("URL", getUrl())
				.append("NAME", getName())
				.append("TMPFILE" , getTmpFile())
				.toString();
	}
	
	
}
